package com.tanhua.server.controller;


import com.tanhua.domain.vo.MomentVo;
import com.tanhua.domain.vo.PageResult;
import com.tanhua.domain.vo.PublishVo;
import com.tanhua.domain.vo.VisitorVo;
import com.tanhua.server.service.CommentService;
import com.tanhua.server.service.MomentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.awt.*;
import java.util.List;

/**
 * @Classname MomentController
 * @Description TODO 圈子
 * @Date 2021/3/10 21:17
 * @Created by gan
 */
@RestController
@RequestMapping("/movements")
public class MomentController {

    @Autowired
    private MomentService momentService;

    @Autowired
    private CommentService commentService;

    //发布动态
    @PostMapping
    public ResponseEntity postMoment( PublishVo vo, MultipartFile[] imageContent){
        //调用业务层
        momentService.postMoment(vo,imageContent);
        //返回结果
        return ResponseEntity.ok(null);
    }

    //查询好友动态
    @GetMapping
    public ResponseEntity queryFriendPublishList(@RequestParam(defaultValue = "1")Long page,@RequestParam(defaultValue = "10")Long pagesize){
        page=page<1?1:page;
        PageResult<MomentVo> pageRequest=momentService.queryFriendPublishList(page,pagesize);
        return ResponseEntity.ok(pageRequest);
    }

    //查询推荐动态
    @GetMapping("/recommend")
    public ResponseEntity queryRecommendPublishList(@RequestParam(defaultValue = "1") int page, @RequestParam(defaultValue = "10") int pagesize){
        page=page<1?1:page;
        PageResult<MomentVo> pageResult = momentService.queryRecommendPublishList(page,pagesize);
        return ResponseEntity.ok(pageResult);
    }

    //查询我的动态
    @GetMapping("/all")
    public ResponseEntity queryMyAlbum(@RequestParam(defaultValue = "1")int page,
                                       @RequestParam(defaultValue = "10")int pagesize,
                                       Long userId){
        page=page<1?1:page;
        PageResult<MomentVo> pageResult=
                momentService.queryMyAlbum(page,pagesize,userId);
        return ResponseEntity.ok(pageResult);
    }

    //点赞
    @GetMapping("/{id}/like")
    public ResponseEntity<Long> like(@PathVariable("id")String publishId){
        Long total=commentService.like(publishId);
        return ResponseEntity.ok(total);
    }

    //取消点赞
    @GetMapping("/{id}/dislike")
    public ResponseEntity<Long> unlike(@PathVariable("id")String publishId){
        Long total=commentService.unlike(publishId);
        return ResponseEntity.ok(total);
    }

    //喜欢
    @GetMapping("/{id}/love")
    public ResponseEntity<Long> love(@PathVariable("id") String publishId) {
        Long total = commentService.love(publishId);
        return ResponseEntity.ok(total);
    }

    //取消喜欢
    @GetMapping("/{id}/unlove")
    public ResponseEntity<Long> unlove(@PathVariable("id") String publishId){
        Long total = commentService.unlove(publishId);
        return ResponseEntity.ok(total);
    }

    //动态详情
    @GetMapping("/{id}")
    public ResponseEntity<MomentVo>queryById(@PathVariable("id")String publishId){
        MomentVo momentVo=momentService.queryById(publishId);
       return ResponseEntity.ok(momentVo);
    }

    //谁看过我
    @GetMapping("/visitors")
    public ResponseEntity queryVisitors(){
        List<VisitorVo>visitorVoList=momentService.queryVisitors();
        return ResponseEntity.ok(visitorVoList);

    }
}
